/**
 * This class represents the search engine that will be created by using the Singleton pattern
 * @author Heather Helton
 *
 */
package com.uah;

import java.net.URI;
import java.net.URISyntaxException;

import android.app.AlertDialog;
import android.content.DialogInterface;


public class SearchEngine {
	//private member variables
	private static SearchEngine instance = null;
	
	protected SearchEngine() {
		//exists only to defeat instantiation
		
	}
	//public methods
	public static SearchEngine getInstance(){
		if(instance == null){
			instance = new SearchEngine();
		}
		
		return instance;
	}
	
	public URI getResults(String userSearch, Semester userSemester){
		
		
		String[] userInput = userSearch.split(" ");
		URI searchResult = null;
		String url = null;
		
		if(userSemester == Semester.Spring13){
			url = "http://www.uah.edu/cgi-bin/schedule.pl?file=sprg2013.html&segment=";
		}
		else if(userSemester == Semester.Summer13R){
			url = "http://www.uah.edu/cgi-bin/schedule.pl?file=sum2013a.html&segment=";
		}
		else if(userSemester == Semester.Summer13first){
			url ="http://www.uah.edu/cgi-bin/schedule.pl?file=sum2013b.html&segment=";
		}
		else if(userSemester == Semester.Summer13second){
			url ="http://www.uah.edu/cgi-bin/schedule.pl?file=sum2013c.html&segment=";
		}
		else if(userSemester == Semester.Fall13){
			url = "http://www.uah.edu/cgi-bin/schedule.pl?file=fall2013.html&segment=";
		}
		
		
		try {
			searchResult = new URI(url + userInput[0].toString());
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return searchResult;
		
		
	}

	public String enteredCollege(String college){
		
		String[] userCollegeInput = college.split(" ");
		
		return userCollegeInput[0].toString();
	}
	

}